﻿using Gui.Pages;
using MaterialDesignThemes.Wpf;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Gui
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow
    {
        MainViewModel vm = new MainViewModel();
        public MainWindow()
        {
            InitializeComponent();
            vm.UserName = "李吉林";
            vm.Position = "打粉工";
            DataContext = vm;
            MainFrame.Content = new Page1(ShowMsg);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            vm.IsChecked = !vm.IsChecked;
        }


        private static void ModifyTheme(bool isDarkTheme)
        {
            var paletteHelper = new PaletteHelper();
            var theme = paletteHelper.GetTheme();

            theme.SetBaseTheme(isDarkTheme ? Theme.Dark : Theme.Light);
            paletteHelper.SetTheme(theme);
        }

        private void MenuPopupButton_OnClick(object sender, RoutedEventArgs e)
        {
            new LoginWindow().Show();
            Close();
        }

        private void MenuToggleButton_OnClick(object sender, RoutedEventArgs e)
        {
            vm.IsChecked = true;
        }

        private void Button_Click1(object sender, RoutedEventArgs e)
        {
            vm.Title = ((Button)sender).Content.ToString();
            vm.IsChecked = false;
            MainFrame.Content = new Page1(ShowMsg);
        }

        private void Button_Click2(object sender, RoutedEventArgs e)
        {
            vm.Title = ((Button)sender).Content.ToString();
            vm.IsChecked = false;
            MainFrame.Content = new Page2();
        }

        private void UpdateProgram()
        {
            string version;
            bool hasNewVersion = AutoUpdate.Work.UpdateWork.HasNewVersion(out version);
            if (hasNewVersion)
            {
                ProcessStartInfo info = new ProcessStartInfo();
                info.UseShellExecute = true;
                info.FileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AutoUpdate.exe");
                info.Arguments = version;
                Process pro = Process.Start(info);
            }

        }

        private void FullScreen()
        {
            WindowState = WindowState.Normal;//还原窗口（非最小化和最大化）
            WindowStyle = WindowStyle.None; //仅工作区可见，不显示标题栏和边框
            ResizeMode = ResizeMode.NoResize;//不显示最大化和最小化按钮
            Topmost = true;    //窗口在最前
            Left = 0.0;
            Top = 0.0;
            Width = SystemParameters.PrimaryScreenWidth;
            Height = SystemParameters.PrimaryScreenHeight;
        }

        public void ShowMsg(string msg)
        {
            var duration = 1;
            MainSnackbar.MessageQueue?.Enqueue(
                msg,
                null,
                null,
                null,
                false,
                true,
            TimeSpan.FromSeconds(duration));
        }
    }

    internal class MainViewModel: NotifyBase
    {
        public string Title
        {
            get { return _title; }
            set
            {
                _title = value;
                RaisePropertyChanged("Title");
            }
        }
        public string UserName
        {
            get { return _userName; }
            set
            {
                _userName = value;
                RaisePropertyChanged("UserName");
            }
        }

        public string Position
        {
            get { return _position; }
            set
            {
                _position = value;
                RaisePropertyChanged("Position");
            }
        }

        public bool IsChecked
        {
            get { return _isChecked; }
            set
            {
                _isChecked = value;
                RaisePropertyChanged("IsChecked");
            }
        }

        private bool _isChecked;
        private string _userName;
        private string _position;
        private string _title;
    }

}
